package in.muton.edushare.pages.common;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.newentities.DeptManager;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.edushare.common.vo.Universities;

public class NewDept extends Panel {

	private static final long serialVersionUID = 5009955650232205829L;

	public NewDept(String id, final IModel<Universities> model) {
		super(id, model);
		WebMarkupContainer wmc = new WebMarkupContainer("msgContainer") {
			@Override
			public boolean isVisible() {
				if(getStatusList().size()>0)
					return true;
				return false;
			}

			private static final long serialVersionUID = 6674357829244135004L;

		};
		add(wmc);
		wmc.add(new ListView<String>("message",new PropertyModel<List<String>>(this, "statusList")) {
			private static final long serialVersionUID = -6031452532751464514L;

			@Override
			protected void populateItem(ListItem<String> arg0) {
				arg0.add(new Label("string", arg0.getModel()));
			}
		});
		Form<Void> f;
		add(f = new Form<Void>("newDept") {
			@Override
			public void onSubmit() {
				setStatusList(new DeptManager(EduShareSession.get()
						.getSessionORMInterface(), model)
						.addNewDepartments(getNewDept()));
				setNewDept("");
			}

			private static final long serialVersionUID = 1L;
		});
		f.add(new TextArea<String>("deptName", new PropertyModel<String>(this,
				"newDept")));

	}

	private String newDept = "";
	private List<String> statusList = new ArrayList<String>();

	public String getNewDept() {
		return newDept;
	}

	public void setNewDept(String newDept) {
		this.newDept = newDept;
	}

	public List<String> getStatusList() {
		return statusList;
	}

	public void setStatusList(List<String> statusList) {
		this.statusList = statusList;
	}
}
